﻿@using hc.epm.DataModel.Business;
@using hc.epm.Common;
@using hc.Plat.Common.Extend;
@model Epm_ProjectCompany
@{
    ViewBag.Title = "AddLinkMan";
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}
<link href="~/Resource/plugins/layui-2.1.2/css/layui.css" rel="stylesheet" />
<style>
    .long-text {
        margin-bottom: 10px;
        height: 35px;
        margin-left: 35px;
    }

    select, input {
        width: 226px;
        height: 35px;
        display: inline-block;
        border: 1px solid #C7C7C7;
        box-sizing: border-box;
        padding-left: 10px;
    }

    .button-group button {
        display: inline-block;
        font-size: 16px;
        letter-spacing: 3px;
        margin: 30px 0 20px 0;
        width: 89px;
        height: 29px;
        border: none;
        border-radius: 3px;
        background-color: #FFA000;
        color: #FEE9D3;
        font-weight: 500;
        margin-left: 204px;
    }

    .tab > div label {
        text-align: right;
        display: inline-block;
        box-sizing: border-box;
        padding-right: 15px;
        width: 125px;
        height: 35px;
        line-height: 35px;
    }

    span.validaterror {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        background: url(/Resource/images/ic_fail.png) no-repeat;
        background-size: 20px 20px;
        background-position: 10px center;
        font-weight: 500;
        color: #FF2525;
        padding-left: 33px;
        font-size: 16px;
    }

    span.validatevalid {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        background: url(/Resource/images/ic_success.png) no-repeat;
        background-size: 22px 22px;
        background-position: 10px center;
    }
</style>
<div class="contentData">
    <form id="mainForm">
        <div class="tab">
            <div class="long-text">
                <label class="label">&nbsp;项目负责人&nbsp;:</label>
                @Html.DropDownList("UserList", null, new { @class = "form-control selectpicker show-tick" })
                <input type="hidden" id="LinkManId_New" name="LinkManId_New" value="@Model.LinkManId" />
                <input type="hidden" id="LinkMan_New" name="LinkMan_New" value="@Model.LinkMan" />
                <input type="hidden" id="Id" name="Id" value="@ViewBag.Id" />
            </div>
            <div class="long-text" style="margin-top:20px;">
                <label class="label">&nbsp;项目负责人电话&nbsp;:</label>
                <input type="text" id="LinkPhone_New" name="LinkPhone_New" value="@Model.LinkPhone" />&nbsp;
            </div>
            <div class="button-group btn-center">
                <button type="button" class="saveBut" id="saveBut">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="~/Resource/scripts/jquery-1.10.2.js"></script>
<script src="~/Resource/scripts/jquery.validate.js"></script>
<script>
    jQuery.validator.addMethod("mobile", function (value, element) {
        var length = value.length;
        var mobile = /^((1[3,5,7,8][0-9]{1})+\d{8})$/
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "手机号码格式错误");

    var validator = $("#mainForm").validate({
        errorClass: "validaterror",
        validClass: "validatevalid",
        errorElement: "span",
        success: function (label) {
            label.addClass("validatevalid").html("&nbsp;");
        },
        rules: {
            LinkMan_New: {
                required: true,
            },
            LinkPhone_New: {
                mobile: true,
            }
        },
        messages: {
            LinkMan_New: {
                required: "项目负责人不能为空",
            },
            LinkPhone_New: {
                mobile: "手机号码格式错误"
            },
        }
    })
    $("#saveBut").click(function () {
        if (!validator.form()) {
            return;
        }
        $("#LinkManId_New").val($("#UserList option:selected").val());
        $("#LinkMan_New").val($("#UserList option:selected").text());
        var search = $("form").serialize();
        $.post("ProjectISPLInkManUpdate", search, function (data) {
            if (data.Flag) {
                parent.layer.msg("操作成功", { time: 1000, icon: 1 }, function () {
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);//关闭窗口
                    var id = $("#Id").val();
                    var ids = parent.$(".datalist").find(".inputId");
                    if (ids.length > 0) {
                        for (var i = 0; i < ids.length; i++) {
                            if (ids[i].value == id) {
                                $(ids[i]).parent().parent().find(".LinkMan").text($("#LinkMan_New").val());
                                $(ids[i]).parent().parent().find(".LinkPhone").text($("#LinkPhone_New").val());
                                $(ids[i]).parent().parent().find(".LinkManEdit").hide();
                            }
                        }
                    }
                    //parent.window.location.reload();
                });
            } else {
                parent.layer.alert(data.Message, { icon: 2 });
            }
        });
    });

</script>